﻿Public Class FormProductEditor

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        'validate other textbox...........
        If Me.txtProductCode.Text = "" Then
            MsgBox("សូមវាយ​បញ្ចូល Product Code")
            Me.txtProductCode.Focus()
            Return
        End If
        If Me.txtProductName.Text = "" Then
            MsgBox("សូមវាយ​បញ្ចូលឈ្មោះ Product")
            Me.txtProductName.Focus()
            Return
        End If
        If Me.cboType.Text = "" Then
            MsgBox("សូមជ្រើសរើសប្រភេទទំនិញ")
            Me.cboType.Focus()
            Return
        End If
        If Me.cboCategory.Text = "" Then
            MsgBox("សូមជ្រើសរើសក្រុមទំនិញ")
            Me.cboCategory.Focus()
            Return
        End If

        If Me.txtPrice.Text = "" Then
            MsgBox("Please input product price!")
            Me.txtPrice.Focus()
            Return
        End If


        If Validator.IsDecimal(txtPrice.Text) = False Then
            MsgBox("Price must be a decimal value!")
            Me.txtPrice.Focus()
            Me.txtPrice.SelectAll()
            Exit Sub
        End If

        If Convert.ToDecimal(Me.txtPrice.Text) <= 0 Then
            MsgBox("Price must be positive")
            Me.txtPrice.Focus()
            Me.txtPrice.SelectAll()
            Exit Sub
        End If
        Cmd.Parameters("@ProductCode") = txtProductCode.Text
        Cmd.Parameters("@ProductName") = txtProductName.Text
        Cmd.Parameters("@CategoryId") = cboCategory.Text
        Cmd.Parameters("@Price") = txtPrice.Text
        Cmd.Parameters("@MinimumPrice") = txtMinimumPrice.Text

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
End Class